window.onload=function () {
	getusername();
  getallbrand();
  isSearch();
}
function GetQueryString(name)
{
     var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)");
     var r = window.location.search.substr(1).match(reg);
     if(r!=null)return  unescape(r[2]); return null;
}
function isSearch() {
    var flag=GetQueryString('flag');
    if(flag==1){
      $.ajax({
      url: 'http://172.18.21.150/ToGo/search',
      type: 'post',
      dataType: 'json',
      data:{keyword:$.cookie('keyword'),pageNum:1,pageSize:10},
      success:function (result) {
          if(result.status=='200'){
            var data=result.data;
            for(var i=0;i<data.length;i++){
                $('#show-child-ul').append('<li class="carshow"><a href="../car/carinfo.html?car_id='+data[i].car_id+'"><div class="car-img"><img src="http://172.18.21.150/'+data[i].photo+'" alt="" style="width:250px;height:190px;">  </div><span>'+data[i].topic+'</span><span style="color:rgb(255,90,55)">￥'+data[i].price+'</span></a></li>');
            }
          }
      },
      error:function () {
        alert('error');
      }
    });
    }
}


function getcarbymodelid(model_id) {
	$.ajax({
      url: 'http://172.18.21.150/ToGo/getCarByModel',
      type: 'post',
      dataType: 'json',
      data:{model_id:model_id,pageNum:1,pageSize:10},
      success:function (result) {
          if(result.status=='200'){
            $('#show-child-ul').html("");
            // $('#show-child').css('background','rgb(255,255,255)');
            var data=result.data;
            for(var i=0;i<data.length;i++){
            	$('#show-child-ul').append('<li class="carshow"><a href="../car/carinfo.html?car_id='+data[i].car_id+'"><div class="car-img"><img src="http://172.18.21.150/'+data[i].photo+'" alt="" style="width:250px;height:190px;">  </div><span>'+data[i].topic+'</span><span style="color:rgb(255,90,55)">￥'+data[i].price+'</span></a></li>');

            }
          }
      },
      error:function () {
        alert('error');
      }
    });
}


function getmodels(brand_id){
  $(this).color="rgb(255,90,55)";
	$.ajax({
		url: 'http://172.18.21.150/ToGo/getModels',
		type: 'post',
		dataType: 'json',
		data: {brand_id: brand_id},
		success:function (result) {
			if(result.status=='200'){
				$('#mid-kind-category').html("");
				var models=result.data;
				for (var i = 0; i < models.length; i++) {
					$('#mid-kind-category').append('<a href="javascript:void(0);" onclick="getcarbymodelid('+models[i].model_id+')">'+models[i].name+'</a>&nbsp;&nbsp;');
				}
			}
		},
		error:function () {
			alert('error');
		}
	});	
}

function getallbrand() {
    $.ajax({
      url: 'http://172.18.21.150/ToGo/listBrandAll',
      type: 'post',
      dataType: 'json',
      success:function (result) {
          if(result.status=='200'){
            var data=result.data;
            for(var i=0;i<data.length;i++){
            	$('#mid-brand-category').append('<a href="javascript:void(0);" onclick="getmodels('+data[i].brand_id+')">'+data[i].brand_name+'</a>&nbsp;&nbsp;');

            }
          }
      },
      error:function () {
        alert('error');
      }
    });
}




